const wx2my = require('../../wx2my');

// pages/agent/agent.js
const app = getApp();
Page({
  data: {
    type: 1,
    allmoney: false,
    showweek: true,
    showmonth: true,
    typeId: '',
    typeNum: 1,
    msg: ''
  },

  right_arrow(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.type);
    var that = this;

    if (e.currentTarget.dataset.type == 3) {
      var num = 3;
      that.setData({
        type: num
      });
    } else {
      var num = e.currentTarget.dataset.type + 1;
      that.setData({
        type: num
      });
    }

    if (num == 1) {
      that.setData({
        typeNum: 1,
        allmoney: false,
        showweek: true,
        showmonth: true
      });
    } else if (num == 2) {
      that.setData({
        typeNum: 2,
        allmoney: true,
        showweek: false,
        showmonth: true
      });
    } else if (num == 3) {
      that.setData({
        typeNum: 3,
        allmoney: true,
        showweek: true,
        showmonth: false
      });
    }

    that.get_shouyi();
  },

  left_arrow(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.type);
    var that = this;

    if (e.currentTarget.dataset.type == 1) {
      var num = 1;
      that.setData({
        type: num
      });
    } else {
      var num = e.currentTarget.dataset.type - 1;
      that.setData({
        type: num
      });
    }

    if (num == 1) {
      that.setData({
        typeNum: 3,
        allmoney: false,
        showweek: true,
        showmonth: true
      });
    } else if (num == 2) {
      that.setData({
        typeNum: 1,
        allmoney: true,
        showweek: false,
        showmonth: true
      });
    } else if (num == 3) {
      that.setData({
        typeNum: 2,
        allmoney: true,
        showweek: true,
        showmonth: false
      });
    }

    that.get_shouyi();
  },

  get_shouyi() {
    let that = this;
    app.wxRequest('shop_home', {
      'shop_token': wx2my.getStorageSync('shop_token'),
      'type': that.data.type
    }, function (res) {
      console.log(res);

      if (res.data.code == 1) {
        that.setData({
          msg: res.data.data
        });
      } else {
        app.toast(res.data.msg);
      }
    });
  },

  onLoad: function (e) {
    this.setData({
      skip: e.type
    });
  },
  onReady: function () {},
  onShow: function () {
    this.get_shouyi();
  },
  order: function () {
    wx2my.navigateTo({
      url: '/pages/order_management/order_management'
    });
  },
  device: function () {
    let that = this;

    if (that.data.skip == 1) {
      wx2my.navigateTo({
        url: '/pages/device_management1/device_management1'
      });
    } else {
      wx2my.navigateTo({
        url: '/pages/device_manage2/device_manage2'
      });
    }
  },

  report(e) {
    wx2my.navigateTo({
      url: '/pages/device_report/device_report'
    });
  },

  apply(e) {
    let that = this;
    wx2my.navigateTo({
      url: '/pages/tx/tx'
    });
  }

});